function showCodeFloat(){
	$("#codePaySuccessFloat").show();
	$("#diagPopAlpha").show();
}

function closeCodeFloat(){
	$("#codePaySuccessFloat").hide();
	$("#diagPopAlpha").hide();
}

///////
//充值验证
$(function(){
	$.validator.setDefaults({submitHandler:function(form){tryUseCode();}});
	$("#codePayForm").validate({
		onkeyup: false, 
		invalidHandler: function(e, validator) {},
		rules: {
			code: {required: true,rechargeCode:true}
		},
 		errorPlacement: function(error, element) {
 			$("#"+element.attr("name")+"PreInfo").hide();
 			$("#"+element.attr("name")+"Info").html(error.attr("class","zf-point"));
 		},
 		success: function(label) {
			label.html("&nbsp;").addClass("mima");
		},
 		messages:{
 			code: {required:"请填写充值卡号",rechargeCode:"充值卡错误或不可用，请重新填写。"}
 		}
	});
});

function tryUseCode(){
	//ajax验证
	var url =  "/st_f/CheckRechargeCode";
	var ret;$.ajax({type:'POST', async:false, url:url, data:"code="+ $("#code").val() + "&use=y"+"&channel="+$("#channel").val(), success:function(data){ret = data;}, dataType:'json'});
	if(ret.flag==true){ 
		$("#codePayMoney").html((ret.money / 100) + "");
		 $("body,html").animate({scrollTop:0},0); //滚动到页面最上方
		showCodeFloat();
	}else{
		if(ret.money<0){
			alert("尝试次数过多，请休息1小时后再来吧~");
		}else{
			alert("充值失败，请重试~");
		}
	}
	
}